#include "../src/wexpxmx.hh"

#include <cassert>
#include <cstdlib>
#include <iostream>

namespace
{
  void
  test_wexpxmx_once (void)
  {
    float x = 100.0 * drand48 () - 50.0;

    float w = flassol::wexpxmx (x);
    float rhs = exp (-w) - w;

    assert (fabs (x - rhs) <= 5e-7 * (1.0 + fabs (x) + fabs (rhs)) ||
            (std::cerr << "x = " << x 
                       << " w = " << w 
                       << " rhs = " << rhs 
                       << std::endl,
             0));
  }

  void
  test_wexpxmx (void)
  {
    for (unsigned int n = 0; n < 1000000; ++n)
      {
        test_wexpxmx_once ();
      }
  }
}

int 
main (void)
{
  srand48 (69);
  test_wexpxmx ();

  return 0;
}
